﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Threading;
using SyncCommon;
using System.IO;

namespace SyncWebSite
{
    public class SyncSouFun : SyncHouseBase
    {
        private Dictionary<string, string> sharedCookies = new Dictionary<string, string>();
        private List<string> retImages = new List<string>();
        private List<string> retthumbImages = new List<string>();

        public Dictionary<string, List<TempA>> RandomFiled = new Dictionary<string, List<TempA>>();
        private string loginName;
        private string targetID;
        private string cityUrl = string.Empty;
        private string _area = "";
        private string cityFlag = "";

        private string Bail = "";
        private string siteBuildingId = "";
        private string siteBuildingName = "";
        private string agentId = "";
        private string leaseEditInfo = "";
        private string tradeEditInfo = "";
        private WebRequest tempRequest;

        //GBK
        private Encoding outpuCoding = Encoding.GetEncoding(936);
        private string homePage = "http://agents0.soufun.com/";
        #region SyncHouseBase

        public SyncSouFun(string user, string password)
            : base(user, password)
        {

        }

        public override bool CheckLogin()
        {
            string checkUrl = homePage + "magent/right.aspx?" + new Random().Next().ToString();
            string loginUrl = "http://agent.soufun.com/DealCenterLogin.aspx";
            WebRequest request = new WebRequest(loginUrl, FormType.FormUrlEncode);
            request.Cookies = sharedCookies;
            request.AddContent("rememberme", "on");
            request.AddContent("str_username", UserName);
            request.AddContent("str_userpwd", Password);
            request.AddContent("Submit1", "");
            string ret = request.SendWaitString();
            string error = "";
            if (CheckLoginStatus(ret, out error))
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        public override bool AddSaleHouse(HouseInfo info, ref string targetID)
        {
            TempContainer.Clear();
            UpdateCurrentStatus(StandardProgress.InitalData);
            //GetCityName(info);
            string error = "";
            bool IsSuccess = false;
            string stat = "";
            try
            {
                if (!CheckLogin())
                {
                    UpdateCurrentStatus(StandardProgress.Failed, "登录失败");
                    return false;
                }
                else
                {
                    string errorInfor = "";
                    if (!CommonCheck(info, true, ref errorInfor))
                    {
                        UpdateCurrentStatus(StandardProgress.Failed, errorInfor);
                        return false;
                    }
                    sharedCookies["global_cookie"] = "vu0oyudg7pxquz1lg74yl9wqom9h73iw1ck";
                    sharedCookies["unique_cookie"] = "U_vu0oyudg7pxquz1lg74yl9wqom9h73iw1ck";
                    WebRequest request;
                    string uploadUrl = this.homePage + "MAgent/House/GetProjData.aspx?";

                    string retHtml = "";
                    //1=住宅，2=商铺，3=写字楼
                    //平房=1,普通住宅=2,商住两用=3,公寓=4,别墅=5,其他=6
                    if (info.HouseType == "3")
                    {
                        request = new WebRequest(homePage + "magent/house/shop/shopSaleInput.aspx");
                        request.ReturnEncoding = outpuCoding;
                        request.Cookies = sharedCookies;
                        retHtml = request.GetResouceStr();
                    }
                    else
                    {
                        request = new WebRequest(homePage + "magent/house/sale/SaleInput.aspx");
                        request.ReturnEncoding = outpuCoding;
                        request.Cookies = sharedCookies;
                        retHtml = request.GetResouceStr();
                    }
                    string[] buildingInfos = this.GetBuilding(info.Estate, info.HouseType).Split(new char[] { '|' });

                    if ((buildingInfos == null) || (buildingInfos.Length < 6))
                    {
                        error = "找不到该小区:" + info.Estate;
                    }
                    else
                    {
                        byte[] responseBytes = null;
                        string uploadUrl1 = this.homePage + "MAgent/House/GetProjData.aspx?newcode=" + HtmlHelper.UrlEncode(buildingInfos[4].Trim(), outpuCoding) +
                            "&purpose=" + HtmlHelper.UrlEncode(buildingInfos[3].Trim(), outpuCoding) + "&num=" + HtmlHelper.UrlEncode(DateTime.UtcNow.ToString(), outpuCoding);
                        request = new WebRequest(uploadUrl1);
                        request.Cookies = sharedCookies;
                        request.ReturnEncoding = outpuCoding;
                        string str13 = "";
                        //request.AddContent("newcode", buildingInfos[4].Trim());
                        //request.AddContent("purpose", buildingInfos[5].Trim());
                        //request.AddContent("num", DateTime.UtcNow.ToString());
                        string retProj = request.GetResouceStr();

                        string[] strArray = retProj.Split(new string[] { "#$%" }, StringSplitOptions.RemoveEmptyEntries);
                        string fieldValue = strArray[0].Trim();
                        string str8 = strArray[1].Trim();

                        string houseUrl = "http://agents0.soufun.com/MAgent/house/inputsave.aspx";
                        string houseAddUrl;// = houseUrl + "?flag=1";
                        request = new WebRequest("http://img.soufun.com/soufun/js/image.js");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest("http://img.soufun.com/soufun/js/image.js");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest(this.homePage + "magent/js/city/%E6%9D%AD%E5%B7%9ECity.js?v=3.947");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest("http://img1.soufun.com/secondhouse/image/magent/js/ClassNumUpDown.js?v=3.947");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest("http://img1.soufun.com/secondhouse/image/magent/js/houseDrafts0516.js");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest(this.homePage + "magent/js/RealHouseUpload.js?v=3.947");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest(this.homePage + "MAgent/js/Root.ComboBox.js?v=3.947");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest(this.homePage + "magent/right.aspx");
                        request.Cookies = sharedCookies;
                        request.ReturnEncoding = outpuCoding;
                        string str32 = request.GetResouceStr();

                        Regex regex10 = new Regex("<li class=\"pt3\">综合能力认证[\\S\\s]*?alt=\"(?<UserState>[\\s\\S]*?)\"");
                        if (regex10.Match(str32).Groups["UserState"].Value == "未通过")
                        {
                            houseAddUrl = houseUrl + "?flag=2";
                        }
                        else
                        {
                            houseAddUrl = houseUrl + "?flag=1";
                        }
                        string text1 = "http://agents0.soufun.com/magent/house/sale/saleinput.aspx";
                        request = new WebRequest(text1);
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();

                        request = new WebRequest(houseAddUrl + "&haveMultipleCity=False&city=" + HtmlHelper.UrlEncode(info.City, outpuCoding), FormType.FormUrlEncode, outpuCoding, outpuCoding);
                        request.SetHeaderValue("Referer", "http://agents0.soufun.com/magent/house/sale/saleinput.aspx");
                        request.Cookies = sharedCookies;
                        tempRequest = request;

                        string viewState = HtmlHelper.GetViewState(retHtml);
                        if (!string.IsNullOrEmpty(viewState))
                        {
                            request.AddContent("__VIEWSTATE", viewState);
                        }
                        InsertImg(retHtml, info);
                        AddCheckBefore("input_y_str_PROJNAME", buildingInfos[0]);
                        AddCheckBefore("input_y_str_ADDRESS", buildingInfos[1]);
                        AddCheckBefore("input_y_str_DISTRICT0", "");
                        AddCheckBefore("input_y_str_COMAREA0", "");
                        AddCheckBefore("str_infocode", "");
                        AddCheckBefore("str_innerid", "");
                        AddCheckBefore("input_str_PropertySubType", "普通住宅");
                        AddCheckBefore("input_PropertySubType", "普通住宅");
                        AddCheckBefore("input_y_str_PAYINFO0", "个人产权");
                        AddCheckBefore("input_y_str_PAYINFO", "个人产权");
                        AddCheckBefore("input_y_num_PRICE", info.Price);
                        AddCheckBefore("input_ROOM", info.Room);
                        AddCheckBefore("input_HALL", info.Hall);
                        AddCheckBefore("input_TOILET", info.WashRoom);
                        AddCheckBefore("input_KITCHEN", "0");
                        AddCheckBefore("input_BALCONY", "0");
                        AddCheckBefore("input_str_HouseStructure", "平层");
                        AddCheckBefore("input_HouseStructure", "平层");
                        AddCheckBefore("input_str_BuildingType", "板楼");
                        AddCheckBefore("input_BuildingType", "板楼");


                        Regex regex = new Regex("\\</span\\> 建筑面积[\\s\\S]*?name=\"(?<guidFlag>[0-9a-z]{17})\"");
                        if (regex.IsMatch(retHtml))
                        {
                            string fieldName = regex.Match(retHtml).Groups["guidFlag"].Value;
                            AddCheckBefore(fieldName, info.Area);
                        }
                        AddCheckBefore("input_y_num_LIVEAREA", "");
                        AddCheckBefore("input_n_str_CREATETIME", info.Age);
                        AddCheckBefore("input_FLOOR", info.CurrentFloor);
                        AddCheckBefore("input_ALLFLOOR", info.Floors);
                        AddCheckBefore("input_n_str_FORWARD", GetToward(info.Toward));
                        AddCheckBefore("input_n_str_FITMENT", GetDecoration(info));
                        if (info.HouseType == "5")
                        {
                            AddCheckBefore("input_n_str_BASESERVICE", "露台,阁楼,游泳池,阳光房");
                        }
                        else
                        {
                            AddCheckBefore("input_n_str_BASESERVICE", "");
                        }
                        AddCheckBefore("input_n_str_LOOKHOUSE", "随时看房");
                        Regex regex2 = new Regex("标[\\s\\S]*?题\\</span>：[\\s\\S]*?name=\"(?<titleFlag>[\\s\\S]*?)\"");
                        if (regex2.IsMatch(retHtml))
                        {
                            string str16 = regex2.Match(retHtml).Groups["titleFlag"].Value;
                            AddCheckBefore(str16, info.Title);
                        }
                        AddCheckBefore("input_n_str_CONTENT", info.Description);
                        AddCheckBefore("input_n_str_TRAFFICINFO", fieldValue);
                        AddCheckBefore("input_n_str_SUBWAYINFO", str8.Substring(0, 20));
                        switch (info.HouseType)
                        {
                            case "3":
                                if (info.HouseType == "3")
                                {
                                    AddCheckBefore("input_y_str_SubType", "住宅底商");
                                }
                                else
                                {
                                    AddCheckBefore("input_n_str_propertyGrade", "甲级");
                                }
                                AddCheckBefore("input_n_num_PropFee", "0");
                                AddCheckBefore("input_n_str_PropCompany", "");
                                AddCheckBefore("input_n_int_IsDivisi", "0");
                                AddCheckBefore("Jfile", "");
                                AddCheckBefore("Pfile", "");
                                AddCheckBefore("Nfile", "");
                                AddCheckBefore("Wfile", "");
                                break;

                            default:
                                AddCheckBefore("Hfile", "");
                                AddCheckBefore("Sfile", "");
                                AddCheckBefore("Xfile", "");
                                break;
                        }
                        string input = retHtml;
                        Regex regex3 = new Regex("inputdrawtext[\\s\\S]*?value=\"(?<inputdrawtextFlag>[\\s\\S]*?)\"");
                        if (regex3.IsMatch(input))
                        {
                            string str17 = regex3.Match(input).Groups["inputdrawtextFlag"].Value;
                            AddCheckBefore("inputdrawtext", str17);
                        }
                        Regex regex4 = new Regex("hdHouseDicCity[\\s\\S]*?value=\"(?<dicCityFlag>[\\s\\S]*?)\"");
                        if (regex4.IsMatch(input))
                        {
                            string str18 = regex4.Match(input).Groups["dicCityFlag"].Value;
                            AddCheckBefore("hdHouseDicCity", str18);
                        }
                        Regex regex5 = new Regex("inputT[\\s\\S]*?value=\"(?<inputTFlag>[\\s\\S]*?)\"");
                        if (regex5.IsMatch(input))
                        {
                            string str19 = regex5.Match(input).Groups["inputTFlag"].Value;
                            AddCheckBefore("inputT", str19);
                        }
                        AddCheckBefore("input_y_str_DISTRICT", buildingInfos[2]);
                        AddCheckBefore("input_y_str_COMAREA", buildingInfos[3]);
                        AddCheckBefore("input_y_str_PURPOSE", buildingInfos[5]);
                        AddCheckBefore("imageCount", "0");
                        AddCheckBefore("coverPhoto", "");
                        string siteBuildingId = buildingInfos[4].Trim();
                        if (string.IsNullOrEmpty(siteBuildingId))
                        {
                            siteBuildingId = this.siteBuildingId;
                        }
                        AddCheckBefore("newcode", siteBuildingId);
                        AddCheckBefore("tempprojimgs", "");
                        AddCheckBefore("newprojimgs", "");
                        AddCheckBefore("UseProjImage", "");

                        AddCheckBefore("input_y_str_MANAGERNAME", UserName);
                        string textOrHiddenValueByName = HtmlHelper.GetTextOrHiddenValueByName(input, "input_Hid");
                        AddCheckBefore("input_Hid", textOrHiddenValueByName);
                        AddCheckBefore("input_y_str_BUSINESSTYPE", "CS");
                        Regex regex6 = new Regex("input_y_str_COMPANYNAME[\\s\\S]*?value=\"(?<companyName>[\\s\\S]*?)\"");
                        if (regex6.IsMatch(input))
                        {
                            string str22 = regex6.Match(input).Groups["companyName"].Value;
                            AddCheckBefore("input_y_str_COMPANYNAME", str22);
                        }
                        Regex regex7 = new Regex("input_y_str_PRICETYPE[\\s\\S]*?value=\"(?<pricetypeName>[\\s\\S]*?)\"");
                        if (regex7.IsMatch(input))
                        {
                            string str23 = regex7.Match(input).Groups["pricetypeName"].Value;
                            AddCheckBefore("input_y_str_PRICETYPE", str23);
                        }
                        AddCheckBefore("hiddenProjname", info.Estate);
                        AddCheckBefore("hdUseMode", "");
                        string str24 = HtmlHelper.GetTextOrHiddenValueByName(input, "guidCode");
                        AddCheckBefore("guidCode", str24);
                        AddCheckBefore("input_DelegateIDAndAgentID", "0");
                        AddCheckBefore("input_draftsID", "0");
                        Regex regex8 = new Regex("\'tempHouseID\'.*?><option>(?<tempHouseId>.*?)</option>");
                        if (regex8.IsMatch(input))
                        {
                            Match match = regex8.Match(input);
                            if (match != null)
                            {
                                string str25 = match.Groups["tempHouseId"].Value;
                                AddCheckBefore("tempHouseID", str25);
                            }
                        }
                      
                        if (!string.IsNullOrEmpty(textOrHiddenValueByName))
                        {
                            string name = "";
                            string str27 = "";
                            this.GetHID(textOrHiddenValueByName, out name, out str27);
                            AddCheckBefore(name, str27);
                        }
                        Regex regex9 = new Regex("name=\"(?<uGuidName>[0-9a-z]{13})\"\\s*?value=\"(?<uGuidValue>[0-9a-z]{11})\"");
                        if (regex9.IsMatch(input))
                        {
                            Match match2 = regex9.Match(input);
                            string str28 = match2.Groups["uGuidName"].Value;
                            string str29 = match2.Groups["uGuidValue"].Value;
                            AddCheckBefore(str28, str29);
                        }
                        BuildRandomData(input);


                        byte[] buffer2 = null;
                        int num2 = 3;
                        request.AllowRedirect = false;
                        PostDataToRequest(request);
                        string str33 = request.SendWaitString();


                        error = "未知";
                        Regex regex11 = new Regex(@"type='text/javascript'>[\s\S]*alert\('(?<err>\S*)'\);");
                        if (regex11.IsMatch(str33))
                        {
                            Match match3 = regex11.Match(str33);
                            int num3 = 0;
                            string str34 = match3.Groups["err"].Value;
                            if (str34.IndexOf("重复房源") > -1)
                            {
                                error = "重复发布房源";
                                IsSuccess = false;
                                num2 = 0;
                            }
                            else if (str34.IndexOf("速度太快") > -1)
                            {
                                IsSuccess = true;
                                //太快提交速度
                                Thread.Sleep(0x4e20);
                            }
                            else if (str34.IndexOf("您今天发布的经纪人房源数量已达到您的日发布量最大值") > -1)
                            {
                                error = "今天发布的数量已达到最大值,不能再继续发布";
                                IsSuccess = false;
                                num2 = 0;
                            }
                            else if (str34.IndexOf("请填写物业名称") > -1)
                            {
                                error = "请填写物业名称";
                                IsSuccess = false;
                                num2 = 0;
                            }
                            else if (str34.IndexOf("请先登录") > -1)
                            {
                                error = "请先登录";
                                IsSuccess = false;
                                num2 = 0;
                            }
                            else if (str34.IndexOf("房源将发布到待发布房源中") > -1)
                            {
                                error = "今日发布数已满，房源将发布到待发布房源中";
                                IsSuccess = true;
                                num2 = 0;
                            }
                            else if (str34.IndexOf("非法录入房源信息") > -1)
                            {
                                error = "售价要大于2万元小于10亿元,建筑面积必须大于2且小于10000";
                                IsSuccess = false;
                                num2 = 0;
                                Thread.Sleep(0x4e20);
                            }
                            else if (str34.IndexOf("错误代码") > -1)
                            {
                                error = str34;
                                IsSuccess = false;
                                num2 = 0;
                            }
                            else
                            {
                                error = str34;
                                IsSuccess = false;
                                num2 = 0;
                            }
                        }
                        if (str33.IndexOf("系统维护中") > -1)
                        {
                            error = "搜房网系统维护中";
                            IsSuccess = false;
                            num2 = 0;
                        }

                        if (str33.IndexOf("建筑面积应大于2") > -1)
                        {
                            error = "建筑面积应大于2小于10000平米。";
                            IsSuccess = false;
                            num2 = 0;
                        }
                        if (error == "未知")
                        {
                            Regex regex12 = new Regex(@"magent/house/SaveFinish.aspx\?flag=1&houseid=(?<ids>\d*)");
                            if (regex12.IsMatch(str33))
                            {
                                IsSuccess = true;
                                Match match4 = regex12.Match(str33);
                                targetID = match4.Groups["ids"].Value;
                                string decode = HtmlHelper.UrlDecode(str33, Encoding.GetEncoding("GB2312"));
                                Regex regex13 = new Regex(@"mess=(?<message>.*)");

                                if (regex13.IsMatch(decode))
                                {
                                    error = regex13.Match(decode).Groups["message"].Value;
                                    if (error == "库存已满")
                                    {
                                        error = "库存已满!房源已发布到待发布房源";
                                    }
                                }
                                else
                                {
                                    error = "";
                                }
                            }
                        }

                    }

                }
                if (IsSuccess)
                {
                    if (string.IsNullOrEmpty(error))
                    {
                        UpdateCurrentStatus(StandardProgress.Sucess, GetImageError(info), targetID, "http://esf.sh.soufun.com/chushou/3_" + targetID + ".htm");
                    }
                    else
                    {
                        UpdateCurrentStatus(StandardProgress.Sucess, error, targetID, "");
                    }
                    return true;
                }
                else
                {
                    if (string.IsNullOrEmpty(error)
                        || error == "未知")
                    {
                        error = "发布失败。发布消息格式不正确";
                    }
                    UpdateCurrentStatus(StandardProgress.Failed, error);
                    return false;
                }
            }
            catch (System.Net.WebException exp)
            {
                error = WebError;
            }
            catch (Exception exp)
            {
                LogCenter.Log("搜房网经纪人信息提交", exp);
                error = exp.Message;
            }
            UpdateCurrentStatus(StandardProgress.Failed, error);
            return false;
        }

        public override bool AddRentHouse(HouseInfo info, ref string targetID)
        {
            TempContainer.Clear();
            UpdateCurrentStatus(StandardProgress.InitalData);
            //GetCityName(info);
            string error = "";
            bool IsSuccess = false;
            try
            {
                if (!CheckLogin())
                {
                    UpdateCurrentStatus(StandardProgress.Failed, "登录失败");
                    return false;
                }
                else
                {
                    string errorInfor = "";
                    if (!CommonCheck(info, false, ref errorInfor))
                    {
                        UpdateCurrentStatus(StandardProgress.Failed, errorInfor);
                        return false;
                    }
                    sharedCookies["global_cookie"] = "72v2lb4ce3k3s29ful11ob91l73hacg7kd3";
                    sharedCookies["unique_cookie"] = "U_6o1wlhxkyy340054775p9e85l2nhadwj2uv*5";
                    sharedCookies["jiatxShopWindow"] = "1";
                    WebRequest request;
                    string uploadUrl = this.homePage + "MAgent/House/GetProjData.aspx?";

                    string retHtml = "";
                    //1=住宅，2=商铺，3=写字楼
                    //平房=1,普通住宅=2,商住两用=3,公寓=4,别墅=5,其他=6
                 
                        //request = new WebRequest(homePage + "magent/house/lease/leaseinput.aspx");

                        request = new WebRequest(homePage + "magent/house/sale/saleinput.aspx");
                        request.ReturnEncoding = outpuCoding;
                        request.Cookies = sharedCookies;
                        retHtml = request.GetResouceStr();
                    
                    string[] buildingInfos = this.GetBuilding(info.Estate, info.HouseType).Split(new char[] { '|' });

                    if ((buildingInfos == null) || (buildingInfos.Length < 6))
                    {
                        error = "找不到该小区:" + info.Estate;
                    }
                    else
                    {
                        byte[] responseBytes = null;
                        string uploadUrl1 = this.homePage + "MAgent/House/GetProjData.aspx?newcode=" + HtmlHelper.UrlEncode(buildingInfos[4].Trim(), outpuCoding) +
                            "&purpose=" + HtmlHelper.UrlEncode(buildingInfos[3].Trim(), outpuCoding) + "&num=" + HtmlHelper.UrlEncode(DateTime.UtcNow.ToString(), outpuCoding);
                        request = new WebRequest(uploadUrl1);
                        request.Cookies = sharedCookies;
                        request.ReturnEncoding = outpuCoding;
                        string str13 = "";
                        //request.AddContent("newcode", buildingInfos[4].Trim());
                        //request.AddContent("purpose", buildingInfos[5].Trim());
                        //request.AddContent("num", DateTime.UtcNow.ToString());
                        string retProj = request.GetResouceStr();

                        string[] strArray = retProj.Split(new string[] { "#$%" }, StringSplitOptions.RemoveEmptyEntries);
                        string fieldValue = strArray[0].Trim();
                        string str8 = strArray[1].Trim();

                        string houseUrl = "http://agents0.soufun.com/MAgent/house/inputsave.aspx";
                        string houseAddUrl ;//= houseUrl + "?flag=1";
                        request = new WebRequest("http://img.soufun.com/soufun/js/image.js");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest("http://img1.soufun.com/secondhouse/image/magent/js/Check0914.js");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest(this.homePage + "magent/js/HousePhotoUpload.js?v=1.017");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest("http://img1.soufun.com/secondhouse/image/magent/js/ClassNumUpDown0907.js");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest("http://img1.soufun.com/secondhouse/image/magent/js/houseDrafts0516.js");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest(this.homePage + "magent/js/RealHouseUpload.js?v=3.947");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest(this.homePage + "MAgent/js/Root.ComboBox.js?v=3.947");
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                        request = new WebRequest(this.homePage + "magent/right.aspx");
                        request.Cookies = sharedCookies;
                        request.ReturnEncoding = outpuCoding;
                        string str32 = request.GetResouceStr();

                        Regex regex10 = new Regex("<li class=\"pt3\">综合能力认证[\\S\\s]*?alt=\"(?<UserState>[\\s\\S]*?)\"");
                        if (regex10.Match(str32).Groups["UserState"].Value == "未通过")
                        {
                            houseAddUrl = houseUrl + "?flag=2";
                        }
                        else
                        {
                            houseAddUrl = houseUrl + "?flag=1";
                        }
                        //string text1;
                        //text1 = "http://agents0.soufun.com/magent/house/sale/saleinput.aspx";
                        //request = new WebRequest(text1);
                        //request.Cookies = sharedCookies;
                        //request.GetResouceStr();

                        request = new WebRequest(houseAddUrl + "&haveMultipleCity=False&city=" + HtmlHelper.UrlEncode(info.City, outpuCoding).ToUpper(), FormType.FormUrlEncode, Encoding.GetEncoding("GB2312"), Encoding.GetEncoding("GB2312"));
                        request.SetHeaderValue("Referer", "http://agents0.soufun.com/magent/house/lease/leaseinput.aspx");
                        request.Cookies = sharedCookies;
                        tempRequest = request;

                        string viewState = HtmlHelper.GetViewState(retHtml);
                        if (!string.IsNullOrEmpty(viewState))
                        {
                            request.AddContent("__VIEWSTATE", viewState);
                        }
                        InsertImg(retHtml, info);
                        AddCheckBefore("input_y_str_PROJNAME", buildingInfos[0]);
                        AddCheckBefore("input_y_str_ADDRESS", buildingInfos[1]);
                        AddCheckBefore("input_y_str_DISTRICT0", "");
                        AddCheckBefore("input_y_str_COMAREA0", "");
                        AddCheckBefore("str_infocode", "");
                        AddCheckBefore("str_innerid", "");
                        AddCheckBefore("input_str_PropertySubType", "普通住宅");
                        AddCheckBefore("input_PropertySubType", "普通住宅");
                        AddCheckBefore("input_y_str_PAYINFO0", "个人产权");
                        AddCheckBefore("input_y_str_PAYINFO", "个人产权");
                        AddCheckBefore("input_y_num_PRICE", info.MonthPrice);
                        Regex regex;
                        #region 出租信息
                        AddCheckBefore("input_y_str_LEASESTYLE", GetHireType(info));
                        AddCheckBefore("input_n_str_leaseRoomType", "主卧");
                        AddCheckBefore("input_n_str_leaseDetail", "性别不限");

                        AddCheckBefore("input_y_str_PAYDETAIL", GetPayment(info));
                        AddCheckBefore("input_y_str_PAYINFO", "月付");

                        regex = new Regex("\\</span\\> 出租面积[\\s\\S]*?name=\"(?<guidFlag>[0-9a-z]{17})\"");
                        if (regex.IsMatch(retHtml))
                        {
                            string fieldName = regex.Match(retHtml).Groups["guidFlag"].Value;
                            AddCheckBefore(fieldName, info.Area);
                        }
                        #endregion


                        AddCheckBefore("input_ROOM", info.Room);
                        AddCheckBefore("input_HALL", info.Hall);
                        AddCheckBefore("input_TOILET", info.WashRoom);
                        AddCheckBefore("input_KITCHEN", "0");
                        AddCheckBefore("input_BALCONY", "0");
                        AddCheckBefore("input_str_HouseStructure", "平层");
                        AddCheckBefore("input_HouseStructure", "平层");
                        AddCheckBefore("input_str_BuildingType", "板楼");
                        AddCheckBefore("input_BuildingType", "板楼");


                       // regex = new Regex("\\</span\\> 出租面积[\\s\\S]*?name=\"(?<guidFlag>[0-9a-z]{17})\"");
                        regex = new Regex("\\</span\\> 建筑面积[\\s\\S]*?name=\"(?<guidFlag>[0-9a-z]{17})\"");
                        if (regex.IsMatch(retHtml))
                        {
                            string fieldName = regex.Match(retHtml).Groups["guidFlag"].Value;
                            AddCheckBefore(fieldName, info.Area);
                        }
                        AddCheckBefore("input_y_num_LIVEAREA", "");
                        AddCheckBefore("input_n_str_CREATETIME", info.Age);
                        AddCheckBefore("input_FLOOR", info.CurrentFloor);
                        AddCheckBefore("input_ALLFLOOR", info.Floors);
                        AddCheckBefore("input_n_str_FORWARD", GetToward(info.Toward));
                        AddCheckBefore("input_n_str_FITMENT", GetDecoration(info));
                        if (info.HouseType == "5")
                        {
                            AddCheckBefore("input_n_str_BASESERVICE", "露台,阁楼,游泳池,阳光房");
                        }
                        else
                        {
                            AddCheckBefore("input_n_str_BASESERVICE", "");
                        }
                        AddCheckBefore("input_n_str_LOOKHOUSE", "随时看房");
                        Regex regex2 = new Regex("标[\\s\\S]*?题\\</span>：[\\s\\S]*?name=\"(?<titleFlag>[\\s\\S]*?)\"");
                        if (regex2.IsMatch(retHtml))
                        {
                            string str16 = regex2.Match(retHtml).Groups["titleFlag"].Value;
                            AddCheckBefore(str16, info.Title);
                        }
                        AddCheckBefore("input_n_str_CONTENT", info.Description);
                        AddCheckBefore("input_n_str_TRAFFICINFO", fieldValue);
                        AddCheckBefore("input_n_str_SUBWAYINFO", str8.Substring(0, 20));
                        switch (info.HouseType)
                        {
                            case "3":
                                if (info.HouseType == "3")
                                {
                                    AddCheckBefore("input_y_str_SubType", "住宅底商");
                                }
                                else
                                {
                                    AddCheckBefore("input_n_str_propertyGrade", "甲级");
                                }
                                AddCheckBefore("input_n_num_PropFee", "0");
                                AddCheckBefore("input_n_str_PropCompany", "");
                                AddCheckBefore("input_n_int_IsDivisi", "0");
                                AddCheckBefore("Jfile", "");
                                AddCheckBefore("Pfile", "");
                                AddCheckBefore("Nfile", "");
                                AddCheckBefore("Wfile", "");
                                break;

                            default:
                                AddCheckBefore("Hfile", "");
                                AddCheckBefore("Sfile", "");
                                AddCheckBefore("Xfile", "");
                                break;
                        }
                        string input = retHtml;
                        Regex regex3 = new Regex("inputdrawtext[\\s\\S]*?value=\"(?<inputdrawtextFlag>[\\s\\S]*?)\"");
                        if (regex3.IsMatch(input))
                        {
                            string str17 = regex3.Match(input).Groups["inputdrawtextFlag"].Value;
                            AddCheckBefore("inputdrawtext", str17);
                        }
                        Regex regex4 = new Regex("hdHouseDicCity[\\s\\S]*?value=\"(?<dicCityFlag>[\\s\\S]*?)\"");
                        if (regex4.IsMatch(input))
                        {
                            string str18 = regex4.Match(input).Groups["dicCityFlag"].Value;
                            AddCheckBefore("hdHouseDicCity", str18);
                        }
                        Regex regex5 = new Regex("inputT[\\s\\S]*?value=\"(?<inputTFlag>[\\s\\S]*?)\"");
                        if (regex5.IsMatch(input))
                        {
                            string str19 = regex5.Match(input).Groups["inputTFlag"].Value;
                            AddCheckBefore("inputT", str19);
                        }
                        AddCheckBefore("input_y_str_DISTRICT", buildingInfos[2]);
                        AddCheckBefore("input_y_str_COMAREA", buildingInfos[3]);
                        AddCheckBefore("input_y_str_PURPOSE", buildingInfos[5]);
                        AddCheckBefore("imageCount", "0");
                        AddCheckBefore("coverPhoto", "");
                        string siteBuildingId = buildingInfos[4].Trim();
                        if (string.IsNullOrEmpty(siteBuildingId))
                        {
                            siteBuildingId = this.siteBuildingId;
                        }
                        AddCheckBefore("newcode", siteBuildingId);
                        AddCheckBefore("tempprojimgs", "");
                        AddCheckBefore("newprojimgs", "");
                        AddCheckBefore("UseProjImage", "");

                        AddCheckBefore("input_y_str_MANAGERNAME", UserName);
                        string textOrHiddenValueByName = HtmlHelper.GetTextOrHiddenValueByName(input, "input_Hid");
                        AddCheckBefore("input_Hid", textOrHiddenValueByName);
                        AddCheckBefore("input_y_str_BUSINESSTYPE", "CZ");
                        Regex regex6 = new Regex("input_y_str_COMPANYNAME[\\s\\S]*?value=\"(?<companyName>[\\s\\S]*?)\"");
                        if (regex6.IsMatch(input))
                        {
                            string str22 = regex6.Match(input).Groups["companyName"].Value;
                            AddCheckBefore("input_y_str_COMPANYNAME", str22);
                        }
                        Regex regex7 = new Regex("input_y_str_PRICETYPE[\\s\\S]*?value=\"(?<pricetypeName>[\\s\\S]*?)\"");
                        if (regex7.IsMatch(input))
                        {
                            string str23 = regex7.Match(input).Groups["pricetypeName"].Value;
                            AddCheckBefore("input_y_str_PRICETYPE", str23);
                        }
                        AddCheckBefore("hiddenProjname", info.Estate);
                        AddCheckBefore("hdUseMode", "");
                        string str24 = HtmlHelper.GetTextOrHiddenValueByName(input, "guidCode");
                        AddCheckBefore("guidCode", str24);
                        AddCheckBefore("input_DelegateIDAndAgentID", "0");
                        AddCheckBefore("input_draftsID", "0");
                        Regex regex8 = new Regex(@"['|""]tempHouseID['|""].*?><option>(?<tempHouseId>.*?)</option>");
                        if (regex8.IsMatch(input))
                        {
                            Match match = regex8.Match(input);
                            if (match != null)
                            {
                                string str25 = match.Groups["tempHouseId"].Value;
                                AddCheckBefore("tempHouseID", str25);
                            }
                        }
                        Regex regex91 = new Regex(@"name=['|""]tempHouseID['|""] value=['|""](?<tempHouseId>.*?)['|""]");
                        if (regex91.IsMatch(input))
                        {
                            Match match = regex91.Match(input);
                            if (match != null)
                            {
                                string str25 = match.Groups["tempHouseId"].Value;
                                AddCheckBefore("tempHouseID", str25);
                            }
                        }
                        if (!string.IsNullOrEmpty(textOrHiddenValueByName))
                        {
                            string name = "";
                            string str27 = "";
                            this.GetHID(textOrHiddenValueByName, out name, out str27);
                            AddCheckBefore(name, str27);
                        }
                        Regex regex9 = new Regex("name=\"(?<uGuidName>[0-9a-z]{13})\"\\s*?value=\"(?<uGuidValue>[0-9a-z]{11})\"");
                        if (regex9.IsMatch(input))
                        {
                            Match match2 = regex9.Match(input);
                            string str28 = match2.Groups["uGuidName"].Value;
                            string str29 = match2.Groups["uGuidValue"].Value;
                            AddCheckBefore(str28, str29);
                        }
                        BuildRandomData(input);
                       
                        Regex regT = new Regex("inpt name=\"(?<name>[0-9a-z]*)\" value=\"(?<val>[0-9a-z]*)\">");
                        if(regT.IsMatch(input))
                        {
                            AddCheckBefore(regT.Match(input).Groups["name"].Value, regT.Match(input).Groups["val"].Value);
                        }
                        byte[] buffer2 = null;
                        int num2 = 3;
                        request.AllowRedirect = false;
                        PostDataToRequest(request);
                        string str33 = request.SendWaitString();


                        error = "未知";
                        Regex regex11 = new Regex(@"type='text/javascript'>[\s\S]*alert\('(?<err>\S*)'\);");
                        if (regex11.IsMatch(str33))
                        {
                            Match match3 = regex11.Match(str33);
                            int num3 = 0;
                            string str34 = match3.Groups["err"].Value;
                            if (str34.IndexOf("重复房源") > -1)
                            {
                                error = "重复发布房源";
                                IsSuccess = false;
                                num2 = 0;
                            }
                            else if (str34.IndexOf("速度太快") > -1)
                            {
                                IsSuccess = true;
                                //太快提交速度
                                Thread.Sleep(0x4e20);
                            }
                            else if (str34.IndexOf("您今天发布的经纪人房源数量已达到您的日发布量最大值") > -1)
                            {
                                error = "今天发布的数量已达到最大值,不能再继续发布";
                                IsSuccess = false;
                                num2 = 0;
                            }
                            else if (str34.IndexOf("请填写物业名称") > -1)
                            {
                                error = "请填写物业名称";
                                IsSuccess = false;
                                num2 = 0;
                            }

                            else if (str34.IndexOf("请先登录") > -1)
                            {
                                error = "请先登录";
                                IsSuccess = false;
                                num2 = 0;
                            }
                            else if (str34.IndexOf("房源将发布到待发布房源中") > -1)
                            {
                                error = "今日发布数已满，房源将发布到待发布房源中";
                                IsSuccess = true;
                                num2 = 0;
                            }
                            else if (str34.IndexOf("非法录入房源信息") > -1)
                            {
                                error = "售价要大于2万元小于10亿元,建筑面积必须大于2且小于10000";
                                IsSuccess = false;
                                num2 = 0;
                                Thread.Sleep(0x4e20);
                            }
                            else if (str34.IndexOf("错误代码") > -1)
                            {
                                error = str34;
                                IsSuccess = false;
                                num2 = 0;
                            }
                            else
                            {
                                error = str34;
                                IsSuccess = false;
                                num2 = 0;
                            }
                        }
                        if (str33.IndexOf("系统维护中") > -1)
                        {
                            error = "搜房网系统维护中";
                            IsSuccess = false;
                            num2 = 0;
                        }
                        if (error == "未知")
                        {
                            Regex regex12 = new Regex(@"magent/house/SaveFinish.aspx\?flag=1&houseid=(?<ids>\d*)");
                            if (regex12.IsMatch(str33))
                            {
                                IsSuccess = true;
                                Match match4 = regex12.Match(str33);
                                targetID = match4.Groups["ids"].Value;
                                string decode = HtmlHelper.UrlDecode(str33, Encoding.GetEncoding("GB2312"));
                                Regex regex13 = new Regex(@"mess=(?<message>.*)");

                                if (regex13.IsMatch(decode))
                                {
                                    error = regex13.Match(decode).Groups["message"].Value;
                                    if (error == "库存已满")
                                    {
                                        error = "库存已满!房源已发布到待发布房源";
                                    }
                                }
                                else
                                {
                                    error = "";
                                }
                            }
                        }
                    }

                }
                if (IsSuccess)
                {
                    if (string.IsNullOrEmpty(error))
                    {

                        UpdateCurrentStatus(StandardProgress.Sucess, GetImageError(info), targetID, "http://zu.sh.soufun.com/chuzu/3_" + targetID + "_1.htm");
                    }
                    else
                    {
                        UpdateCurrentStatus(StandardProgress.Sucess, error, targetID, "");
                    }
                    return true;
                }
                else
                {
                    if (string.IsNullOrEmpty(error)
                      || error == "未知")
                    {
                        error = "发布失败。发布消息格式不正确";
                    }
                    UpdateCurrentStatus(StandardProgress.Failed, error);
                    return false;
                }
            }
            catch (System.Net.WebException exp)
            {
                error = WebError;
            }
            catch (Exception exp)
            {
                LogCenter.Log("搜房网经纪人信息提交", exp);
                error = exp.Message;
            }
            UpdateCurrentStatus(StandardProgress.Failed, error);
            return false;
        }
        public override bool DeleteSaleHouse(HouseInfo info, string targetID)
        {
            UpdateCurrentStatus(StandardProgress.InitalData);
            try
            {
                if (CheckLogin())
                {
                    string error = "";
                    int flag = 1;

                    string address = "http://agents0.soufun.com/MAgent/house/HouseList.aspx?businesstype=cs&sortby=%C4%AC%C8%CF%C5%C5%D0%F2&flag={0}&mendianid=0&txtInnerId=&txtProjName=&txtPriceMin=&txtPriceMax=&txtRoom=0&imageField=%CB%D1+%CB%F7&Order=%C4%AC%C8%CF%C5%C5%D0%F2&PurposeSelect=%C8%AB%B2%BF&pagesize=20&txtHouseId={1}&hidagentid={2}";
                    string agentID = this.GetAgentId();

                    WebRequest request = new WebRequest(string.Format(address, "1", targetID, agentID));
                    request.ReturnEncoding = outpuCoding;
                    request.Cookies = sharedCookies;

                    string htm = request.GetResouceStr();
                    if (htm.IndexOf("houseid=" + targetID) > 0)
                    {
                        flag = 1;
                        //HtmlHelper.GetViewState(htm);
                    }
                    else
                    {
                        request = new WebRequest(string.Format(address, "2", targetID, agentID));
                        request.ReturnEncoding = outpuCoding;
                        request.Cookies = sharedCookies;
                        htm = request.GetResouceStr();
                        if (htm.IndexOf("houseid=" + targetID) > 0)
                        {
                            flag = 2;
                        }
                        else
                        {
                            UpdateCurrentStatus(StandardProgress.Failed, "此房源不存在");
                            return false;
                        }
                    }
                    string ramKey = "";
                    string ramValue = "";
                    GetRamdonStr(htm, ref ramKey, ref ramValue);
                    string deleteUrl = "http://agents0.soufun.com/Magent/House/HouseListAction.aspx?businesstype=cs&page=1&pagesize=20&flag={0}&mendianID=0&dealbath=true&agentid={1}";

                    request = new WebRequest(string.Format(deleteUrl, flag, agentID), FormType.FormUrlEncode);
                    request.Cookies = sharedCookies;
                    request.ReturnEncoding = outpuCoding;
                    request.AddContent("pageurl", string.Format("/Magent/House/HouseList.aspx?businesstype=cs&page=1&pagesize=20&flag={0}&order=addtimedesc", flag));
                    request.AddContent("action", "delhouse");
                    request.AddContent("houseIDs", targetID);
                    request.AddContent(ramKey, ramValue);
                    UpdateCurrentStatus(StandardProgress.PosData, "");
                    string str21 = request.SendWaitString();
                    if (str21.IndexOf("删除成功") > -1)
                    {
                        UpdateCurrentStatus(StandardProgress.Sucess, "");
                        return true;
                    }
                    if (str21.IndexOf("houseid=" + targetID) > 0)
                    {
                        error = "该房源在待发布状态中，不能删除。";

                    }
                    if (str21.IndexOf("删除失败") > -1)
                    {
                        error = "删除失败";
                    }
                    else
                    {
                        error = "该房源不存在，不能删除。";
                    }

                    UpdateCurrentStatus(StandardProgress.Failed, error);
                    return false;
                }
                else
                {
                    UpdateCurrentStatus(StandardProgress.Failed, "登陆失败");
                    return false;
                }
            }
            catch (System.Net.WebException exp)
            {
                UpdateCurrentStatus(StandardProgress.Failed, WebError);
                return false;
            }
        }

        public override bool DeleteRentHouse(HouseInfo info, string targetID)
        {
            UpdateCurrentStatus(StandardProgress.InitalData);
            try
            {

                if (CheckLogin())
                {
                    string error = "";
                    int flag = 1;

                    string address = "http://agents0.soufun.com/MAgent/house/HouseList.aspx?businesstype=cz&sortby=%C4%AC%C8%CF%C5%C5%D0%F2&flag={0}&mendianid=0&txtInnerId=&txtProjName=&txtPriceMin=&txtPriceMax=&txtRoom=0&imageField=%CB%D1+%CB%F7&Order=%C4%AC%C8%CF%C5%C5%D0%F2&PurposeSelect=%C8%AB%B2%BF&pagesize=20&txtHouseId={1}&hidagentid={2}";
                    string agentID = this.GetAgentId();

                    WebRequest request = new WebRequest(string.Format(address, "1", targetID, agentID));
                    request.ReturnEncoding = outpuCoding;
                    request.Cookies = sharedCookies;

                    string htm = request.GetResouceStr();
                    if (htm.IndexOf("houseid=" + targetID) > 0)
                    {
                        flag = 1;
                        //HtmlHelper.GetViewState(htm);
                    }
                    else
                    {
                        request = new WebRequest(string.Format(address, "2", targetID, agentID));
                        request.ReturnEncoding = outpuCoding;
                        request.Cookies = sharedCookies;
                        htm = request.GetResouceStr();
                        if (htm.IndexOf("houseid=" + targetID) > 0)
                        {
                            flag = 2;
                        }
                        else
                        {
                            UpdateCurrentStatus(StandardProgress.Failed, "此房源不存在");
                            return false;
                        }
                    }
                    string ramKey = "";
                    string ramValue = "";
                    GetRamdonStr(htm, ref ramKey, ref ramValue);
                    string deleteUrl = "http://agents0.soufun.com/Magent/House/HouseListAction.aspx?businesstype=cz&page=1&pagesize=20&flag={0}&mendianID=0&dealbath=true&agentid={1}";

                    request = new WebRequest(string.Format(deleteUrl, flag, agentID), FormType.FormUrlEncode);
                    request.Cookies = sharedCookies;
                    request.ReturnEncoding = outpuCoding;
                    request.AddContent("pageurl", string.Format("/Magent/House/HouseList.aspx?businesstype=cz&page=1&pagesize=20&flag={0}&order=addtimedesc", flag));
                    request.AddContent("action", "delhouse");
                    request.AddContent("houseIDs", targetID);
                    request.AddContent(ramKey, ramValue);
                    UpdateCurrentStatus(StandardProgress.PosData, "");
                    string str21 = request.SendWaitString();
                    if (str21.IndexOf("删除成功") > -1)
                    {
                        UpdateCurrentStatus(StandardProgress.Sucess, "");
                        return true;
                    }
                    if (str21.IndexOf("houseid=" + targetID) > 0)
                    {
                        error = "该房源在待发布状态中，不能删除。";

                    }
                    if (str21.IndexOf("删除失败") > -1)
                    {
                        error = "删除失败";
                    }
                    else
                    {
                        error = "该房源不存在，不能删除。";
                    }

                    UpdateCurrentStatus(StandardProgress.Failed, error);
                    return false;
                }
                else
                {
                    UpdateCurrentStatus(StandardProgress.Failed, "登陆失败");
                    return false;
                }
            }
            catch (System.Net.WebException exp)
            {
                UpdateCurrentStatus(StandardProgress.Failed, WebError);
                return false;
            }
        }
        public override bool RefreshSaleHouse(HouseInfo info, string targetID)
        {
            return InnerRefresh(targetID, "cs");
        }

        private bool InnerRefresh(string targetID, string type)
        {
            UpdateCurrentStatus(StandardProgress.InitalData);
            try
            {
                if (CheckLogin())
                {

                    //http://agents0.soufun.com/Magent/House/HouseListAction.aspx?businesstype=cs&page=1&pagesize=20&flag=1&agentid=160765855&mendianID=0&action=refhouse&houseid=42159691&pageurl=%2fmagent%2fhouse%2fhouselist.aspx%3fbusinesstype%3dcs%26page%3d1%26pagesize%3d20%26flag%3d1&b73a208finput36c5=eeb85732inputadd7
                    string radName = "";
                    string radValue = "";
                    GetRamdom(ref radName, ref  radValue);
                    string agent = GetAgentId();

                    string url = string.Format("http://agents0.soufun.com/Magent/House/HouseListAction.aspx?businesstype={0}&page=1&pagesize=20&flag=1&agentid={1}&mendianID=0&action=refhouse&houseid={2}&pageurl=%2fmagent%2fhouse%2fhouselist.aspx%3fbusinesstype%3dcs%26page%3d1%26pagesize%3d20%26flag%3d1", type, agentId, targetID);
                    if (!string.IsNullOrEmpty(radName))
                    {
                        url = url + "&" + radName + "=" + radValue;
                    }
                    WebRequest request = new WebRequest(url);
                    request.Cookies = sharedCookies;
                    request.ReturnEncoding = outpuCoding;
                    UpdateCurrentStatus(StandardProgress.PosData);

                    string status = request.GetResouceStr();
                    if (status.Contains("刷新成功"))
                    {
                        UpdateCurrentStatus(StandardProgress.Sucess, "");
                        return true;
                    }
                    else
                    {
                        string error = "刷新失败。房源必须处于已发布状态，且每天只能刷新10条信息";

                        UpdateCurrentStatus(StandardProgress.Failed, string.IsNullOrEmpty(error) ? "刷新信息失败" : error);
                        LogCenter.LogMessage("刷新信息失败。提交值ID:" + targetID ?? "");
                        return false;
                    }
                }
                else
                {
                    UpdateCurrentStatus(StandardProgress.Failed, "登陆失败");
                    return false;
                }
            }
            catch (System.Net.WebException exp)
            {
                UpdateCurrentStatus(StandardProgress.Failed, WebError);
                return false;
            }
        }
        public override bool RefreshRentHouse(HouseInfo info, string targetID)
        {
            return InnerRefresh(targetID, "cz");
        }

        #endregion

        #region HelpFunction
        private string getCityflag(string inputStr)
        {
            try
            {
                Regex regex = new Regex("initUpload\\(\"Hfile\",\"3\",\"(?<cityFlag>[\\s\\S]*?)\"");
                if (regex.IsMatch(inputStr))
                {
                    string str = regex.Match(inputStr).Groups["cityFlag"].Value;
                    this.cityFlag = str;
                    return str;
                }
                Regex regex2 = new Regex("initUpload\\(\"Nfile\",\"6\",\"(?<cityFlag>\\S*?)\",\"N\"\\);");
                if (regex2.IsMatch(inputStr))
                {
                    string str2 = regex2.Match(inputStr).Groups["cityFlag"].Value;
                    this.cityFlag = str2;
                    return str2;
                }
                return this.cityFlag;
            }
            catch (Exception)
            {
                return this.cityFlag;
            }
        }

        private void InsertImg(string inputStr, HouseInfo info)
        {
            retImages.Clear();
            errorImage=0;
            int count = 1;
            if (info.Images != null && info.Images.Length > 0)
            {
                string status = "";
                foreach (string url in info.Images)
                {
                    try
                    {
                        WebRequest request = new WebRequest(url);
                        Stream stream = request.GetResouce();
                        string name = url.Substring(url.LastIndexOf('/') + 1);


                        request = new WebRequest("http://img1u.soufun.com/upload/agents/houseinfo2?channel=agent.houseinfo&city=sh&kind=houseinfo&sid=947187156&backurl=http%3a%2f%2fagents0.soufun.com%2fMagent%2fPicInterface%2fSingleHousePicUploadFinish.aspx&type=3&drawtext=", FormType.MultiPart);
                        request.AllowRedirect = true;
                        request.Cookies = sharedCookies;
                        request.ReturnEncoding = outpuCoding;
                        request.AddContent("picType", "5");//5室内照 1小区 3户型
                        request.AddFile(name, "Hfile", stream);
                        string ret = request.SendWaitString();
                        if (ret.Contains("window.parent.UploadImageForOne"))
                        {
                            //window.parent.UploadImageForOne('http://img1.soufunimg.com/agents2/2012_11/26/22/58/31/sh/houseinfo/404100106400.jpg','w:600+h:450+s:36380+m:100','',3)
                            Regex reg = new Regex(@"window\.parent\.UploadImageForOne\('(?<url>.*?)','(?<des>.*?)'");
                            Match ma = reg.Match(ret);
                            if (ma.Success)
                            {
                                AddCheckBefore("txtImage_3_" + count.ToString(), ma.Groups["url"].Value);
                                AddCheckBefore("inpUrlsExtend_3_" + count.ToString(), ma.Groups["des"].Value);
                                AddCheckBefore("inputIsProj_3_" + count.ToString(), "undefined");
                                AddCheckBefore("inputOrderIndex_3_" + count.ToString(), count.ToString());
                                count++;
                                continue;
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                      
                    }
                    errorImage++;
                }
            
            }
            
            //    this.getCityflag(inputStr);
            //    int index = 0;
            //    string imgHrefs = "";
            //    WebRequest request = new WebRequest("");
            //    if (!string.IsNullOrEmpty(context.SiteHouseId))
            //    {
            //        if (context.ImgFields.Find(c => c.ImgOper != ImgOperator.Original) == null)
            //        {
            //            return;
            //        }
            //        DataTable houseLeasePublishImgTitle = null;
            //        if (context.HouseType == HouseTypeEnum.HouseLease)
            //        {
            //            houseLeasePublishImgTitle = HouseManager.GetHouseLeasePublishImgTitle(context.HouseId, context.SiteInfo.SiteId);
            //        }
            //        else
            //        {
            //            houseLeasePublishImgTitle = HouseManager.GetHouseTradePublishImgTitle(context.HouseId, context.SiteInfo.SiteId);
            //        }
            //        if (houseLeasePublishImgTitle != null)
            //        {
            //            foreach (DataRow row in houseLeasePublishImgTitle.Rows)
            //            {
            //                index++;
            //                switch (((ImgCatalog)Enum.Parse(typeof(ImgCatalog), row["CatalogId"])))
            //                {
            //                    case ImgCatalog.RoomModel:
            //                        data.Fields.Add(new TextField("txtImageDes_3_" + index, row["Title"], this.encdoing));
            //                        data.Fields.Add(new TextField("txtImage_3_" + index, row["TargetImgUrl"], this.encdoing));
            //                        data.Fields.Add(new TextField("photoId_3_" + index, this.GetImgIds(row["TargetImgUrl"], context), this.encdoing));
            //                        break;

            //                    case ImgCatalog.RoomInside:
            //                        data.Fields.Add(new TextField("txtImageDes_1_" + index, row["Title"], this.encdoing));
            //                        data.Fields.Add(new TextField("txtImage_1_" + index, row["TargetImgUrl"], this.encdoing));
            //                        data.Fields.Add(new TextField("photoId_1_" + index, this.GetImgIds(row["TargetImgUrl"], context), this.encdoing));
            //                        break;

            //                    case ImgCatalog.Building:
            //                        data.Fields.Add(new TextField("txtImageDes_2_" + index, row["Title"], this.encdoing));
            //                        data.Fields.Add(new TextField("txtImage_2_" + index, row["TargetImgUrl"], this.encdoing));
            //                        data.Fields.Add(new TextField("photoId_2_" + index, this.GetImgIds(row["TargetImgUrl"], context), this.encdoing));
            //                        break;
            //                }
            //                object obj2 = imgHrefs;
            //                imgHrefs = string.Concat(new object[] { obj2, row["TargetImgUrl"], "-", row["Title"], "," });
            //            }
            //        }
            //    }
            //    if (context.ImgFields != null)
            //    {
            //        List<ImgField> list = BasePubs.ExistsImgFieldList(context.ImgFields.FindAll(c => string.IsNullOrEmpty(c.SiteImgUrlOrId) && !string.IsNullOrEmpty(c.ImgPath)));
            //        string agentId = this.GetAgentId(context);
            //        string str3 = "";
            //        if (context.HouseType == HouseTypeEnum.HouseTrade)
            //        {
            //            str3 = "cs";
            //        }
            //        else if (context.HouseType == HouseTypeEnum.HouseLease)
            //        {
            //            str3 = "cz";
            //        }
            //        string url = this.cityUrl + "MAgent/house/UploadImages.aspx?businesstype=" + str3 + "&houseid=" + context.SiteHouseId + "&agentid=" + agentId + "&flag=1&mendianid=0";
            //        string refer = this.cityUrl + "magent/house/houselist.aspx?flag=1&businesstype=" + str3;
            //        string fieldValue = this.GetViewState(url, new PostData(base._httpClient), context, refer);
            //        TextField field2 = new TextField("__VIEWSTATE", fieldValue, this.encdoing);
            //        List<FieldData> oriFieldDatas = new List<FieldData> {
            //    field2
            //};
            //        string str7 = "";
            //        foreach (ImgField field3 in list)
            //        {
            //            index++;
            //            if (field3.ImgOper == ImgOperator.Insert)
            //            {
            //                switch (field3.ImgCatalog)
            //                {
            //                    case ImgCatalog.RoomModel:
            //                        {
            //                            this.UploadRoomModelImg(context.HouseType, field3, oriFieldDatas, data, context, index, ref imgHrefs, url);
            //                            continue;
            //                        }
            //                    case ImgCatalog.RoomInside:
            //                        {
            //                            this.UploadRoomInsideImg(context.HouseType, field3, oriFieldDatas, data, context, index, ref imgHrefs, url);
            //                            continue;
            //                        }
            //                    case ImgCatalog.Building:
            //                        {
            //                            this.UploadBuildingImg(context.HouseType, field3, oriFieldDatas, data, context, index, ref imgHrefs, url);
            //                            continue;
            //                        }
            //                }
            //            }
            //            else if ((field3.ImgOper == ImgOperator.Delete) && !string.IsNullOrEmpty(field3.SiteImgUrlOrId))
            //            {
            //                string imgIds = this.GetImgIds(field3.SiteImgUrlOrId, context);
            //                if (!string.IsNullOrEmpty(imgIds))
            //                {
            //                    str7 = str7 + imgIds;
            //                }
            //            }
            //        }
            //        if (context.HouseType == HouseTypeEnum.HouseTrade)
            //        {
            //            str3 = "cs";
            //            data.Fields.Add(new TextField("backurl", "%2fmagent%2fhouse%2fhouselist.aspx%3fflag%3d2%26businesstype%3dcs", this.encdoing));
            //            data.Fields.Add(new TextField("input_y_str_BUSINESSTYPE", "cs", this.encdoing));
            //        }
            //        else if (context.HouseType == HouseTypeEnum.HouseLease)
            //        {
            //            str3 = "cz";
            //            data.Fields.Add(new TextField("backurl", "%2fmagent%2fhouse%2fhouselist.aspx%3fflag%3d2%26businesstype%3dcz", this.encdoing));
            //            data.Fields.Add(new TextField("input_y_str_BUSINESSTYPE", "cz", this.encdoing));
            //        }
            //        string format = this.cityUrl + "MAgent/house/UploadImages.aspx?businesstype=" + str3 + "&houseid=" + context.SiteHouseId + "&agentid=" + agentId + "&flag={0}&mendianid=0";
            //        string uploadUrl = string.Format(format, 1);
            //        data.Fields.Add(new TextField("__VIEWSTATE", fieldValue, this.encdoing));
            //        data.Fields.Add(new TextField("file3", "", this.encdoing));
            //        data.Fields.Add(new TextField("file1", "", this.encdoing));
            //        data.Fields.Add(new TextField("file2", "", this.encdoing));
            //        data.Fields.Add(new TextField("inputdrawtext", "", this.encdoing));
            //        data.Fields.Add(new TextField("imageCount", index, this.encdoing));
            //        if (!string.IsNullOrEmpty(str7))
            //        {
            //            data.Fields.Add(new TextField("HdDelImageId", str7, this.encdoing));
            //        }
            //        data.Fields.Add(new TextField("coverPhoto", "", this.encdoing));
            //        data.Fields.Add(new TextField("HdDelImageId", "", this.encdoing));
            //        data.Fields.Add(new TextField("tempprojimgs", "", this.encdoing));
            //        data.Fields.Add(new TextField("newprojimgs", "", this.encdoing));
            //        data.Fields.Add(new TextField("UseProjImage", "", this.encdoing));
            //        data.Fields.Add(new TextField("actionStr", "modify", this.encdoing));
            //        byte[] responseBytes = null;
            //        string msg = "";
            //        int num2 = 3;
            //        while (num2-- > 0)
            //        {
            //            if (data.UploadData(uploadUrl, "POST", out responseBytes, out msg))
            //            {
            //                string str12 = this.encdoing.GetString(responseBytes);
            //                if (string.IsNullOrEmpty(str12) || !str12.Contains("您没有权限"))
            //                {
            //                    break;
            //                }
            //                uploadUrl = string.Format(format, 2);
            //            }
            //        }
            //    }
        }

        private void GetRamdonStr(string html, ref string key, ref string value)
        {
            Regex reg = new Regex("<spa name=\"(?<key>.*?)\" value=\"(?<value>.*?)\" >");
            Match ma = reg.Match(html);
            if (ma.Success)
            {
                key = ma.Groups["key"].Value;
                value = ma.Groups["value"].Value;
            }
        }

        private bool Logined(string checkUrl)
        {
            //请先登录
            WebRequest requect = new WebRequest(checkUrl);
            requect.Cookies = sharedCookies;
            requect.ReturnEncoding = outpuCoding;
            string temp = requect.GetResouceStr();
            if (temp.Contains("请先登录"))
            {
                return false;
            }
            return true;
        }

        private void GetHID(string oriHidStr, out string name, out string value)
        {
            name = "";
            value = "";
            string[] strArray = oriHidStr.Split(new char[] { '_' });
            int num = Convert.ToInt32(strArray[0]);
            int num2 = Convert.ToInt32(strArray[2]);
            string str = strArray[1];
            string str2 = "";
            string str3 = "";
            int startIndex = 0;
            int num4 = 0;
            int num5 = 0;
            while (startIndex < (num + num2))
            {
                if (num4 < num)
                {
                    num4++;
                    str2 = str2 + str.Substring(startIndex, 1);
                    startIndex++;
                }
                if (num5 < num2)
                {
                    num5++;
                    str3 = str3 + str.Substring(startIndex, 1);
                    startIndex++;
                }
            }
            name = str2;
            value = str3;
        }


        private string GetBuilding(string newBuildName, string houseType)
        {
            string str = "";
            string districtUrl = homePage + "MAgent/House/getDistrictList.aspx";
            //WebRequest request = new WebRequest(districtUrl);
            //request.Cookies = sharedCookies;

            string strType = "";
     
                strType = "住宅";
           
            string strBuild = HttpUtility.UrlEncode(newBuildName, outpuCoding);
            string final = "?key=" + strBuild + "&type=\"" + HttpUtility.UrlEncode(strType, outpuCoding) + "\"&num=Fri%20May%2020%202011%2021:23:00%20GMT+0800";
            string uploadUrl = districtUrl + final;
            WebRequest request = new WebRequest(uploadUrl);
            request.Cookies = sharedCookies;
            request.ReturnEncoding = outpuCoding;
            string ret = request.GetResouceStr();


            if (string.IsNullOrEmpty(ret))
            {
                return "";
            }
            string[] strArray = ret.Split(new char[] { '~' });
            if ((strArray == null) || (strArray.Length <= 0))
            {
                return str;
            }
            for (int i = 0; i < strArray.Length; i++)
            {
                string tempStr = strArray[i];
                if (i == 0)
                {
                    str = tempStr;
                }
                string[] strArray2 = tempStr.Split(new char[] { '|' });
                if (((strArray2 != null) && (strArray2.Length > 0) && (strArray2[0].Trim() == newBuildName.Trim())))
                {
                    return tempStr;
                }
            }
            return str;
        }

        public void GetRamdom(ref string name, ref string value)
        {
            string url = "http://agents0.soufun.com/magent/house/houselist.aspx?businesstype=cs";
            WebRequest request = new WebRequest(url);
            request.Cookies = sharedCookies;
            request.ReturnEncoding = outpuCoding;
            string str8 = request.GetResouceStr();
            if (!string.IsNullOrEmpty(str8))
            {
                Regex regex = new Regex("spa name=\"(?<convertName>\\S*?)\" value=\"(?<convertValue>\\S*?)\"");
                if (regex.IsMatch(str8))
                {
                    Match match = regex.Match(str8);
                    if (match != null)
                    {
                        name = match.Groups["convertName"].Value;
                        value = match.Groups["convertValue"].Value;
                    }
                }
            }
        }
        private void BuildRandomData(string urlStr)
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            Regex regex = new Regex("\\<input type=\"hidden\" name\\s?=\"(?<inputGuidText>[\\s\\S]*?)\"(?<inputGuidValue>[\\s\\S]*?)/>");
            if (regex.IsMatch(urlStr))
            {
                foreach (Match match in regex.Matches(urlStr))
                {
                    if (match != null)
                    {
                        string _ranGuidText;
                        string str = match.Groups["inputGuidText"].Value;
                        if (str.Trim().ToLower() != "temphouseid")
                        {
                            _ranGuidText = str;
                            string str2 = string.Empty;


                            str2 = match.Groups["inputGuidValue"].Value;
                            if (!string.IsNullOrEmpty(str2))
                            {
                                Regex regex2 = new Regex("value=\"(?<inputGuidValue>[\\s\\S]*?)\"");
                                if (regex2.IsMatch(str2))
                                {
                                    str2 = regex2.Match(str2).Groups["inputGuidValue"].Value;
                                }
                            }
                            dictionary[_ranGuidText] = str2;

                        }
                    }
                }
            }
            Regex regex3 = new Regex("\\<select[^\\<\\>]*?name=['\"](?<selName>[^\\<\\>]*?)['\"][^\\<\\>]*?\\>\\<option\\>(?<optionVal>[\\s\\S]*?)\\</option\\>\\</select\\>");
            if (regex3.IsMatch(urlStr))
            {
                foreach (Match match2 in regex3.Matches(urlStr))
                {
                    string str3 = match2.Groups["selName"].Value;
                    string str4 = match2.Groups["optionVal"].Value;
                    if (!string.IsNullOrEmpty(str3))
                    {
                        string key = str3.Trim();
                        if (!dictionary.ContainsKey(key))
                        {
                            dictionary.Add(key, str4);
                        }
                    }
                }
            }
            Regex regex4 = new Regex("\\<input(?<value1>[^\\<\\>]*?)name=['\"](?<name>[^\\+\\<\\>]*?)['\"](?<value2>[^\\<\\>]*?)/\\>");
            if (regex4.IsMatch(urlStr))
            {
                foreach (Match match3 in regex4.Matches(urlStr))
                {
                    Predicate<string> predicate = null;
                    string _nameStr = match3.Groups["name"].Value;
                    if (!string.IsNullOrEmpty(_nameStr))
                    {
                        _nameStr = _nameStr.Trim();
                        if (_nameStr != "input_str_PropertySubType")
                        {
                            if (dictionary.ContainsKey(_nameStr))
                            {
                                continue;
                            }
                        }

                        string str6 = "";
                        string str7 = match3.Groups["value1"].Value ?? "";
                        Regex regex5 = new Regex("style=['\"]display:none[\"']|type=['\"]hidden['\"]");
                        string str8 = match3.Groups["value2"].Value ?? "";
                        if (!string.IsNullOrEmpty(str7) && regex5.IsMatch(str7))
                        {
                            str6 = str7;
                        }
                        if ((string.IsNullOrEmpty(str6) && !string.IsNullOrEmpty(str8)) && regex5.IsMatch(str8))
                        {
                            str6 = str8;
                        }
                        if (!string.IsNullOrEmpty(str6))
                        {
                            Regex regex6 = new Regex("checked=[\"']checked[\"']");
                            bool flag = regex6.IsMatch(str7);
                            if (!flag)
                            {
                                flag = regex6.IsMatch(str8);
                            }
                            string str9 = "";
                            Regex regex7 = new Regex("value=[\"'](?<val1>(\\S*?))[\"']");
                            if (regex7.IsMatch(str7))
                            {
                                str9 = regex7.Match(str7).Groups["val1"].Value ?? "";
                            }
                            if (regex7.IsMatch(str8))
                            {
                                str9 = regex7.Match(str8).Groups["val1"].Value ?? "";
                            }
                            if (string.IsNullOrEmpty(str9) && flag)
                            {
                                str9 = "on";
                            }
                            dictionary.Add(_nameStr, str9);
                        }
                    }
                }
            }
            foreach (KeyValuePair<string, string> pair in dictionary)
            {
                string _ranGuidText = pair.Key;
                string beforeName = string.Empty;
                string fieldValue = pair.Value;
                if (!string.IsNullOrEmpty(_ranGuidText))
                {
                    string str11 = string.Empty;
                    int index = urlStr.IndexOf(_ranGuidText);
                    if (index > -1)
                    {
                        str11 = urlStr.Substring(index);
                    }
                    if (!string.IsNullOrEmpty(str11))
                    {
                        Regex regex8 = new Regex(@"\<input(?<inputContext>[\s\S]*?)\>");
                        if (regex8.IsMatch(str11))
                        {
                            MatchCollection matchs4 = regex8.Matches(str11);
                            if ((matchs4 != null) && (matchs4.Count > 0))
                            {
                                Match match4 = matchs4[0];
                                string str12 = match4.Groups["inputContext"].Value;
                                if (!string.IsNullOrEmpty(str12))
                                {
                                    Regex regex9 = new Regex("name[\\s]*?=[\\s]*?['\"][\\s]*?(?<name>[\\s\\S]*?)[\\s]*?['\"]");
                                    if (regex9.IsMatch(str12))
                                    {
                                        Match match5 = regex9.Match(str12);
                                        if (match5 != null)
                                        {
                                            beforeName = match5.Groups["name"].Value;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(beforeName))
                {
                    if (CheckExist(_ranGuidText) > -1)
                    {
                        continue;
                    }
                    int index = CheckExist(beforeName);
                    if (index > -1)
                    {

                        TempContainer.Insert(index, new TempA() { Key = _ranGuidText, Value = fieldValue });
                    }
                }
            }
        }


        public string GetToward(string toward)
        {
            //当前 1:东 2:南 3:西 4:北 5:南北 6:东西 7:东南 8:西南 9:东北 10:西北 11:其他
            // 东 南 西 北 东南 西南 西北 东北 南北 东西
            if (toward == "1")
            {
                return "东";
            }
            if (toward == "2")
            {
                return "南";
            }
            if (toward == "3")
            {
                return "西";
            }
            if (toward == "4")
            {
                return "北";
            }

            if (toward == "5")
            {
                return "南北";
            }
            if (toward == "6")
            {
                return "东西";
            }
            if (toward == "7")
            {
                return "东南";
            }
            if (toward == "8")
            {
                return "西南";
            }

            if (toward == "9")
            {
                return "东北";
            }
            if (toward == "10")
            {
                return "西北";
            }
            return "东";
        }


        private bool CheckLoginStatus(string output, out string ret)
        {
            if (output.Contains("magent/DealSeparateLogin.aspx?city=") || (output.IndexOf("{\"result\":\"100\"") > -1))
            {
                if (output.IndexOf("isagtuser\":\"0") > -1)
                {
                    ret = "账号不能登陆,请到搜房网中申请搜房帮帐号.";
                    return false;
                }
                else
                {
                    Regex reg = new Regex(@"window.location.replace\(\'(?<url>.*?)\'\)");
                    if (reg.IsMatch(output))
                    {
                        WebRequest request = new WebRequest(reg.Match(output).Groups["url"].Value);
                        request.Cookies = sharedCookies;
                        request.GetResouceStr();
                    }
                }
            }
            else
            {
                int num2 = 2;
                for (string str6 = @"errorMsg=([\S\s]*?)'\)"; num2-- > 0; str6 = "\"errormsg\":\"([\\S\\s]*?)\"")
                {
                    Regex regex = new Regex(str6);
                    if (regex.IsMatch(output))
                    {
                        Match match = regex.Match(output);
                        int num3 = 0;
                        foreach (Group group in match.Groups)
                        {
                            if (num3 == 1)
                            {
                                if (!string.IsNullOrEmpty(group.Value))
                                {
                                    ret = "原因:" + HttpUtility.UrlDecode(group.Value);
                                    return false;
                                }
                                num2 = -1;
                                break;
                            }
                            num3++;
                        }
                    }
                }
            }
            ret = "";
            return true;
        }

        private string GetDecoration(HouseInfo info)
        {
            //当前 1:毛胚 2:简装 3:精装 4:豪装
            //目标 豪华装修,精装修,中装修,简装修,毛坯
            switch (info.Decoration)
            {
                case "1":
                    return "毛坯";
                case "2":
                    return "简装修";
                case "3":
                    return "精装修";
                case "4":
                    return "豪华装修";
                default:
                    return "简装修";
            }
        }


        public void AddCheckBefore(string key, string value)
        {
            TempContainer.Add(new TempA() { Key = key, Value = value });
        }

        public int CheckExist(string key)
        {
            for (int i = 0; i < TempContainer.Count; i++)
            {
                if (TempContainer[i].Key == key)
                {
                    return i;
                }
            }
            return -1;
        }

        private void PostDataToRequest(WebRequest request)
        {
            for (int i = 0; i < TempContainer.Count; i++)
            {
                request.AddContent(TempContainer[i].Key, TempContainer[i].Value);
            }
        }
        private string GetAgentId()
        {
            try
            {
                string uploadUrl = "http://agents0.soufun.com/magent/Right.aspx";
                WebRequest request = new WebRequest(uploadUrl);
                request.ReturnEncoding = outpuCoding;
                request.Cookies = sharedCookies;
                string input = request.GetResouceStr();

                Regex regex = new Regex(@"编 [\s\S]*号：(?<agentId>\S*)\</dd\>");
                int num3 = 2;
                while (num3-- > 0)
                {
                    if (regex.IsMatch(input))
                    {
                        Match match = regex.Match(input);
                        this.agentId = match.Groups["agentId"].Value ?? "";
                        return this.agentId;
                    }
                    regex = new Regex("编<span class=\"pl24\">号：</span>(?<agentId>[\\s\\S]*?)</li>");
                }

            }
            catch (Exception exception)
            {
                LogCenter.Log(exception);
                return "";
            }
            return "";
        }

        public string GetHireType(HouseInfo info)
        {
            //当前 0.单间出租 1.床位出租 2.整套出租
            //目标 文字: 合租  整租
            switch (info.HireType)
            {
                case "0":
                    return "合租";
                case "1":
                    return "合租";
                case "2":
                    return "整租";
            }
            return "整租";
        }

        public string GetPayment(HouseInfo info)
        {
            //当前 1:付一押一 2:付二押一 3:付三押一 4:付六押一
            //文字 押一付一，押二付一，押三付一，押二付三，无押付半年 面议 押一付三
            switch (info.PayType)
            {
                case "0":
                    return "面议";
                case "1":
                    return "押一付一";
                case "3":
                    return "押一付三";
                case "4":
                    return "押一付半年";
            }
            return "面议";
        }

        public List<TempA> TempContainer = new List<TempA>();
        #endregion

        #region 编辑功能
        public override bool OpenEidt(WebBrowserOp op, HouseInfo info)
        {
            try
            {
                if (CheckLogin())
                {
                    op.CustomerInterval = 3000;
                    if (info.TradeType == TradeType.Sale)
                    {
                        string post = "http://agents0.soufun.com/magent/house/sale/saleinput.aspx";
                        foreach (KeyValuePair<string, string> k in sharedCookies)
                        {
                            WebBrowserOp.InternetSetCookie(post, k.Key, k.Value);
                        }
                        op.HouseInformation = info;
                        op.Navigate(post);
                        op.Completed += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(op_Sale_Completed);
                    }
                    else
                    {
                        string post = "http://agents0.soufun.com/magent/house/lease/leaseinput.aspx";
                        foreach (KeyValuePair<string, string> k in sharedCookies)
                        {
                            WebBrowserOp.InternetSetCookie(post, k.Key, k.Value);
                        }
                        op.HouseInformation = info;
                        op.Navigate(post);
                        op.Completed += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(op_Rent_Completed);
                    }

                }
                else
                {
                    return false;
                }
            }
            catch
            {
                op.Navigate("http://sh.mysupa.com/");
            }
            return true;
        }
        void op_Sale_Completed(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
        {
            WebBrowserOp cl = sender as WebBrowserOp;
            HouseInfo info = cl.HouseInformation;
            cl.SetValueByID("input_PROJNAME", info.Estate);


            cl.SetValueByID("input_PRICE", info.Price);

            cl.SetValueByID("input_ROOM", info.Room);
            cl.SetValueByID("input_HALL", info.Hall);
            cl.SetValueByID("input_TOILET", info.WashRoom);

            cl.SetValueByAttribute("maxlength", "8", info.Area);

            cl.SetValueByID("input_CREATETIME", info.Age);


            cl.SetValueByID("input_FLOOR", info.CurrentFloor);
            cl.SetValueByID("input_ALLFLOOR", info.Floors);


            cl.CheckByName_Value("input_n_str_FORWARD",  GetToward(info.Toward),true);
            cl.CheckByName_Value("input_n_str_FITMENT", GetDecoration(info), true);
            cl.SetValueByAttribute("maxlength", "60", info.Title);

            cl.SetAllFrameValByAttr("contentEditable", "true", info.Description);

           
        }
        void op_Rent_Completed(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
        {
            WebBrowserOp cl = sender as WebBrowserOp;
            HouseInfo info = cl.HouseInformation;
            cl.SetValueByID("input_PROJNAME", info.Estate);


            cl.SetValueByID("input_PRICE", info.MonthPrice);

            cl.SetValueByID("input_ROOM", info.Room);
            cl.SetValueByID("input_HALL", info.Hall);
            cl.SetValueByID("input_TOILET", info.WashRoom);

            cl.SetValueByAttribute("maxlength", "8", info.Area);

            cl.SetValueByID("input_CREATETIME", info.Age);

            cl.CheckByName_Value("input_y_str_PAYDETAIL", GetPayment(info),true);
            cl.SetValueByID("input_FLOOR", info.CurrentFloor);
            cl.SetValueByID("input_ALLFLOOR", info.Floors);


            cl.CheckByName_Value("input_n_str_FORWARD", GetToward(info.Toward), true);
            cl.CheckByName_Value("input_n_str_FITMENT", GetDecoration(info), true);
            cl.SetValueByAttribute("maxlength", "60", info.Title);
            cl.SetAllFrameValByAttr("contentEditable", "true", info.Description);
          
        }
        #endregion
    }

    public class TempA
    {
        public string Key;
        public string Value;
    }

}
